////////////////////////////////////////
// stringUtil.cpp
// Name:  Stephen Durfey
// Class: CS335
// Time:  Tue, Thurs 1:00-2:15pm
// Professor: Dr. Michael Poor

#include "stringUtil.h"

using namespace std;

////////////////////////////////////////
// 'readMultiWord' reads a multiword string
//     terminated by 'sep' from 'infile' into 's';
// returns true if a multiword string read;
// returns false if the first word is a separator ('sep')
// Example: if 'infile' contains "Los Angeles # California"
//     then "Los Angeles" is stored in 's' and
//     position of 'infile' is now at "California"

bool readMultiWord(string &fullWord, ifstream & inFile, const string & sep)
{
    string word;
    int wordCount = 0;
    
    inFile >> word;
    wordCount++;
    
    //if word is a "#", then either an end of file or end of line
    //has been reached, and returns false.
    if(word == sep)  
    {
        return false;
    }
    else
    {
        //loop is used to add parts of the word together (if multiple parts exist)
        //up until a "#" is encountered.
        while(word != sep)      
        {
            if(wordCount == 1)
                fullWord = word;
            else
                fullWord += (" " + word);
            
            inFile >> word;
            wordCount++;
        }
        
        return true;
    }
}
    
    

